//2009/08/30 21:19:23
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class RoyalTreasurer
{
public:
    int minimalArrangement(vector <int> A, vector <int> B)
    {
        int s = 0;
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        for (int i=0; i<A.size(); i++)
            s += A[i] * B[B.size() -1 - i];
        return s;
    }
};
